﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace UI.Forms
{
    public partial class Warehouse_U : FormBase1
    {
        public delegate void DoAction(string wid);//如果有参数的话，定义参数 
        int count = 0;
        public DoAction FatherRefresh;
        private SVC.client.Warehouse wh=null;
        public Warehouse_U(SVC.client.Warehouse _wh)
        {
            InitializeComponent();
            wh = _wh;
        }

        private void btn_new_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            valildbefore();
            if (dxValidationProvider1.Validate())
            {
                wh.shopcode = te_WarehouseID.Text;
                wh.WarehouseName = te_name.Text;
                wh.shopcode = lue_shop.EditValue.ToString();
                wh.Remarks = te_remarks.Text;
                string result = my.bw.Warehouse_Update(wh, my.ACID);
                if(string.IsNullOrWhiteSpace(result))
                {
                    count++;
                    this.Close();
                }
                else
                {
                    Comm.ShowErorr(result);
                }
            }
        }

        private void valildbefore()
        {
            te_WarehouseID.Text = te_WarehouseID.Text;
            te_name.Text = te_name.Text.Trim();
            te_remarks.Text = te_remarks.Text.Trim();
        }

        private void reset()
        {
            te_WarehouseID.Text = "";
            te_name.Text ="";
            lue_shop.EditValue = null;
            te_remarks.Text = "";
        }

        private void btn_nowclose_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            valildbefore();
            if (dxValidationProvider1.Validate())
            {
                SVC.client.Warehouse wh = new SVC.client.Warehouse();
                wh.shopcode = te_WarehouseID.Text;
                wh.WarehouseName = te_name.Text;
                wh.shopcode = lue_shop.EditValue.ToString();
                wh.Remarks = te_remarks.Text;

                string result = my.bw.Warehouse_Add(wh, my.ACID);
                if (string.IsNullOrWhiteSpace(result))
                {
                    FatherRefresh("");
                    this.Close();
                }
                else
                {
                    Comm.ShowErorr(result);
                }
            }
        }

        private void Warehouse_N_Load(object sender, EventArgs e)
        {
            lue_shop.Properties.DataSource = my.bw.View_shop_lite_Get(my.ACID);
            te_WarehouseID.Text = wh.WarehouseID;
            te_name.Text = wh.WarehouseName;
            lue_shop.EditValue = wh.shopcode;
            te_remarks.Text = wh.Remarks;
        }

        private void Warehouse_U_FormClosed(object sender, FormClosedEventArgs e)
        {
            if (count>0)
            {
                FatherRefresh(wh.WarehouseID);
            }
        }
    }
}